package com.qidianit.mes.pro.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.pro.ProductionOrder;
import com.qidianit.mes.pojo.pro.Workflow;
import com.qidianit.mes.pro.service.ProductionOrderService;
import com.qidianit.mes.pro.service.WorkflowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/productionOrder")
@CrossOrigin
public class ProductionOrderController {
    @Autowired
    private ProductionOrderService productionOrderService;
    @GetMapping("/list")
    public Result<PageInfo<ProductionOrder>> selectList(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize,
            ProductionOrder productionOrder,
            @RequestParam(required = false) String materialName
    ){
        return productionOrderService.selectList(pageNum, pageSize, productionOrder, materialName);
    }

    @GetMapping("/{id}")
    public Result<ProductionOrder> queryByCode(@PathVariable("id") Long id){
        return productionOrderService.queryByCode(id);
    }

    @PostMapping("/add")
    public  Result<ProductionOrder> add(@RequestBody ProductionOrder productionOrder){
        return productionOrderService.add(productionOrder);
    }

    @PutMapping("/update")
    public Result<ProductionOrder> updateById(@RequestBody ProductionOrder productionOrder){
        return productionOrderService.updateById(productionOrder);
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable("id") Long id){
        return productionOrderService.deleteById(id);
    }

}
